import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:svgaplayer_flutter/player.dart';

class BtChatVoiceRecordWidget extends StatefulWidget {
  const BtChatVoiceRecordWidget({super.key, required this.isVoiceRecordCanSend});

  final bool isVoiceRecordCanSend;

  @override
  State createState() => _BtChatVoiceRecordState();
}

class _BtChatVoiceRecordState extends State<BtChatVoiceRecordWidget> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      color: const Color(0x99000000),
      child: Stack(
        children: [
          Positioned.fill(
            child: InkWell(
                onTap: () {
                  context.router.back();
                },
                child: const SizedBox()),
          ),
          Align(
            alignment: Alignment.bottomCenter,
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                widget.isVoiceRecordCanSend
                    ? const SizedBox(
                        width: 131,
                        height: 84,
                        child: SVGASimpleImage(
                          assetsName: "assets/svga/bt_voice_anim.svga",
                        ),
                      )
                    : Image.asset(
                        'assets/images/bt_icon_voice_wave_red.png',
                        width: 131,
                        height: 84,
                      ),
                const SizedBox(
                  height: 111,
                ),
                Text(
                  widget.isVoiceRecordCanSend ? "Release Send" : "Release Cancel",
                  style: const TextStyle(
                    fontSize: 16,
                    color: Colors.white,
                  ),
                ),
                const SizedBox(height: 8),
                ClipPath(
                  clipper: BottomArcClipper(),
                  child: Container(
                    width: double.infinity,
                    height: 158,
                    color: Colors.white,
                    padding: const EdgeInsets.only(bottom: 52),
                    child: Align(
                      alignment: Alignment.bottomCenter,
                      child: Image.asset(
                        widget.isVoiceRecordCanSend
                            ? 'assets/images/bt_icon_voice_green.png'
                            : 'assets/images/bt_icon_voice_gray.png',
                        width: 62,
                        height: 62,
                      ),
                    ),
                  ),
                )
              ],
            ),
          ),
        ],
      ),
    );
  }
}

class BottomArcClipper extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    var path = Path();
    var arcH = 44.0;
    path.moveTo(0, arcH);
    path.quadraticBezierTo(size.width / 2, 0, size.width, arcH);
    path.lineTo(size.width, size.height);
    path.lineTo(0, size.height);
    path.close();
    return path;
  }

  @override
  bool shouldReclip(covariant CustomClipper<Path> oldClipper) {
    return true;
  }
}
